#!/bin/sh

OS=FreeBSD
OS_VERSION=7

DRIVER_HDR="ringmap.h"
DRIVER_SRC_DIR="../em/"
LIBPCAP_SRC_DIR="../libpcap/"
USERCLIENTS_DIR="../userspace/"

# schould check version of system.
check_os() {
	uname |grep $OS || { echo "Wrond OS" ; exit 1 ; }
}

make_driver() {
	cd $DRIVER_SRC_DIR
	make clean
	make || { echo "Error by compiling driver" ; return 1 ; }
	cd -

}

make_libpcap() {
	# Clean last build, make and install 
	cd $LIBPCAP_SRC_DIR
	# cp ${DRIVER_SRC_DIR}${DRIVER_HDR} .
	make clean
	make || { echo "Error by compiling libpcap" ; return 1 ; }
	cd -
}


###################################
### 		S T A R T           ###
###################################

# Check OS
echo
echo "CHECK OS:"
echo "=================================================================="
check_os
echo "=================================================================="
echo

sleep 2

# Build driver
echo
echo "MAKE DRIVER FOR CAPTURING WITH MAPPED BUFFERS:"
echo "=================================================================="
make_driver
if [ $? -eq 1 ]
then 
	echo "Stop building! Exit!"
	exit 1;
fi
echo "=================================================================="
echo

sleep 3

# Build libpcap
echo
echo "MAKE libpcap FOR ringmap DRIVER:"
echo "=================================================================="
make_libpcap
if [ $? -eq 1 ]
then 
	echo "Stop building! Exit!"
	exit 1;
fi
